#278 migration support for database delivered in framework#286
#278 migration support for database delivered in framework#286tomasz-czyzak wants to merge 1 commit intoproject-imas:masterfrom tomasz-czyzak:Issue278
Conversation
|
Feel free to close it if #268 fixes it |
|
|
||
| if (modelBundle == nil) | ||
| { | ||
| modelBundle = [NSBundle mainBundle]; |
There was a problem hiding this comment.
Here the main bundle is fetched and then later added to an array on line 983. However according to Apple documentation on the mainBundle method the method can return nil. Therefore an error will occur when attempting to add nil to an array.
This method may return a valid bundle object even for unbundled apps. It may also return nil if the bundle object could not be created, so always check the return value.
You could add a additional check and error code for this case if you wanted to make this code as resilient as possible.
typedef NS_ENUM(NSInteger, EncryptedStoreError)
{
EncryptedStoreErrorIncorrectPasscode = 6000,
EncryptedStoreErrorMigrationFailed,
EncryptedStoreErrorModelLoadFailed
};
if (modelBundle == nil)
{
if (error)
{
NSDictionary * userInfo = @{EncryptedStoreErrorMessageKey : @"Main Bundle not found, cannot load model"};
*error = [NSError errorWithDomain: EncryptedStoreErrorDomain
code: EncryptedStoreErrorModelLoadFailed
userInfo: userInfo];
}
return NO;
}
There was a problem hiding this comment.
While I agree with you about handling mainBundle method however it is kind of overkill since if mainBundle is nil then we are in more serious troubles than handling error correctly,
Also getting modelBundle from mainBundle assumes that model is delivered inside app while issue which has been fixed by this PR is to migrate correctly model delivered in framework
Anyway feel free to raise separate PR for fixing mainBundle potential nil return.
There was a problem hiding this comment.
Ok, perhaps it would be an extreme edge case.
No description provided.